//
//  DSPageView.m
//  DemoTest
//
//  Created by DaShuEdu on 2017/5/11.
//  Copyright © 2017年 DaShuEdu. All rights reserved.
//

#import "DSPageView.h"
#import "DSPageStyle.h"
#import "DSTitleView.h"
#import "DSContentView.h"

@interface DSPageView ()

@property (nonatomic, strong) DSPageStyle *style;
@property (nonatomic, strong) NSArray *titles;
@property (nonatomic, strong) NSArray *childVcs;
@property (nonatomic, strong) UIViewController *parentVc;

@end

@implementation DSPageView

- (instancetype)initWithFrame:(CGRect)frame
                        sytle:(DSPageStyle *)style
                       titles:(NSArray<NSString *> *)titles
                     childVcs:(NSArray<UIViewController *> *)childVcs
                     parentVc:(UIViewController *)parentVc {
    if (self = [super initWithFrame:frame]) {
        self.style = style;
        self.titles = titles;
        self.childVcs = childVcs;
        self.parentVc = parentVc;
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    // 创建TitleView
    CGRect titleFrame = CGRectMake(0, 0, self.bounds.size.width, self.style.titleHeight);
    DSTitleView *titleView = [[DSTitleView alloc] initWithFrame:titleFrame style:self.style titles:self.titles];
    titleView.backgroundColor = [UIColor whiteColor];
    [self addSubview:titleView];
    
    // 创建ContentView
    CGRect contentFrame = CGRectMake(0, self.style.titleHeight, self.bounds.size.width, self.bounds.size.height - self.style.titleHeight);
    DSContentView *contentView = [[DSContentView alloc] initWithFrame:contentFrame childVcs:self.childVcs parentVc:self.parentVc];
    contentView.backgroundColor = [UIColor whiteColor];
    [self addSubview:contentView];
    
    titleView.delegate = contentView;
    contentView.delegate = titleView;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
